﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Cineman.ViewModels;
using System.Net.Http;
using HtmlAgilityPack;
using System.Threading.Tasks;

namespace Cineman
{
    public partial class MovieDetailsPage : PhoneApplicationPage
    {
        public MovieDetailsPage()
        {
            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            //MovieData movie = new MovieData();
            //Overlay.Visibility = Visibility.Visible;
            //OverlayProgressBar.IsIndeterminate = true;
            //DataContext = App.ViewModel;
            //Overlay.Visibility = Visibility.Collapsed;
            //OverlayProgressBar.IsIndeterminate = false;
        }
        
        // When page is navigated to set data context to selected item in list
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (DataContext == null)
            {
                string selectedIndex = "";
                string selectedGroup = "";
                if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
                {
                    NavigationContext.QueryString.TryGetValue("selectedGroup", out selectedGroup);
                    int index = int.Parse(selectedIndex);
                    if (selectedGroup == "Today") {
                        DataContext = App.ViewModel.Today.Items[index];
                    }
                    else if (selectedGroup == "ComingSoon") {
                        DataContext = App.ViewModel.ComingSoon.Items[index];
                    }
                }
            }
        }
    }
}